<template>
  <div>
    <router-link to="/my">
    <div class="head">
      <div class="head-left"><img src="../../assets/icon/common-left.png" alt=""></div>
      <div class="head-right">密碼找回</div>
    </div>
      </router-link>
    <div class="input-item">
      <input type="email"  v-model="email" placeholder="請輸入郵箱">
    </div>
    <div class="input-item">
      <input type="password" v-model="password" placeholder="請輸入新密碼">
    </div>
    <div class="input-item">
      <input type="password" v-model="passwords" placeholder="确认新密碼">
    </div>
    <div class="input-item">
      <input type="text" v-model="msg_code" placeholder="請輸入郵箱驗證碼">
      <div class="get-code-btn" @click="wentCode()"  v-show="show">獲取驗證碼</div>
      <div class="get-code-btn" style="color: #2a62cc" v-show="!show">{{count}}</div>
    </div>
    <mt-button type="primary" @click="niuBi" class="login-submit" :style="{marginTop:'14px'}">確認修改</mt-button>

  </div>
</template>

<script>
  import {Field, Header, Button, MessageBox} from 'mint-ui';
  import Vue from 'vue';
  import {respass} from 'api/respass'
  import {goCode} from 'api/getCode'

  Vue.component(Header.name, Header);
  Vue.component(Field.name, Field);
  Vue.component(Button.name, Button);
  export default {
    name: "respass",
    data() {
      return {
        msg_code:'',
        count: '',
        show: true,
        email:'',
        password:'',
        passwords:'',
        timer: null,

      }
    },
    methods: {

      //修改密码
      niuBi() {
        if (this.email==''){
          MessageBox.alert('郵箱不能为空');
          return
        }

        if (this.password==''){
          MessageBox.alert('密码不能为空');
          return
        }

          respass({
            username:this.email,
            upwd:this.password,
            upwd2:this.passwords,
            phonecode:this.msg_code
          }).then((data) => {
              MessageBox.alert(data.data)
          })

      },
      wentCode(){

          goCode({mail:this.email}).then((data)=>{
            if (data.errorCode!=0){
              MessageBox.alert(data.msg)
            }else {
              const TIME_COUNT = 60;
              if (!this.timer) {
                this.count = TIME_COUNT;
                this.show = false;
                this.timer = setInterval(() => {
                  if (this.count > 0 && this.count <= TIME_COUNT) {
                    this.count--;
                  } else {
                    this.show = true;
                    clearInterval(this.timer);
                    this.timer = null;
                  }
                }, 1000)

              }
            }
          });





      },
      allMoney() {
        this.amount = this.myMoney
      }
    },



  }
</script>

<style scoped>
  .head {
    width: 100%;
    display: flex;
    height: 40px;
    flex-direction: row;
    font-size: 16px;
    font-weight: bold;
    line-height: 40px;
  }

  .head-left {
    width: 40%;
    height:40px ;
    margin-left: 4%;
  }
  .head-left img {
    width: 12px;
    margin-top: 10px;
    margin-left: 4px
  ;
  }
  .head-right {
    width: 40%;
  }



  .get-code-btn {
    width: 89px;
    height: 34px;
    text-align: center;
    line-height: 34px;
    color: #0a356c;
    font-weight: bold;

    margin-left: 10px;
    cursor: pointer;
    font-size: 12px;
  }

  .input-item #msg-code {
    width: 80px;
  }

  .input-item {
    margin-bottom: 16px;
    width: 80%;
    display: flex;
    align-items: center;
    height: 56px;
    margin-left: 10%;
    margin-top: 20px;
  }

  .input-item input {
    flex: 1;
    padding-left: 11px;
    width: 50%;
    color: #C0C4CC;
    font-size: 11px;
    height: 34px;
    border: none;
    border-bottom: 1px solid #4681f5;
  }

  .login-submit {
    width: 80%;
    margin-left: 10%;
    height: 42px;
    margin-top: 45px;
    background: #409EFF;
    color: #FFFFFF;
    font-weight: 100;
    font-size: 16px;
  }
</style>
